
from utils import *

class Mouse(pygame.sprite.Sprite):
    def __init__(self, *keys):
        super().__init__()
        self.size = keys[0]  # 设置圆的大小
        self.rect = pygame.Rect(WIDTH / 2 - self.size, HEIGHT / 2 - self.size, self.size * 2, self.size * 2)  # 实则是一个正方形
    def update(self, screen, *args):
        if pygame.mouse.get_focused():  # 如果存在于页面内
            self.rect.center = pygame.mouse.get_pos()
        # 限制球不能半身跑到边框上
        if self.rect.x < 0:
            self.rect.x = 0
        elif self.rect.x > WIDTH - self.rect.w:
            self.rect.x = WIDTH - self.rect.w
        elif self.rect.y < 0:
            self.rect.y = 0
        elif self.rect.y > HEIGHT - self.rect.h:
            self.rect.y = HEIGHT - self.rect.h
        pygame.draw.circle(screen, (0, 255, 0), [self.rect.center[0], self.rect.center[1]], self.size)  # 根据圆心画圆
